home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / wics.zip / SBAR.CPP < prev    next >
C/C++ Source or Header  |  1993-03-03  |  6KB  |  260 lines

  1. //==============================================================================================
  2. //
  3. //    Windows Interface Construction Set
  4. //    Version 1.00
  5. //
  6. //    SBAR.CPP - Status Bar Class
  7. //    Copyright ⌐ 1993 by Microdyne Development Technologies
  8. //    All rights reserved.
  9. //==============================================================================================
  10.  
  11. #include "sbar.h"
  12. #include "string.h"
  13.  
  14. TStatusBar::TStatusBar (PTWindowsObject AParent, WORD wHeight) :
  15.         TWindow (AParent, NULL)
  16. {
  17.     Attr.Id = 20;
  18.     Attr.Style = WS_CHILD | WS_VISIBLE | WS_GROUP | WS_TABSTOP | WS_CLIPCHILDREN;
  19.     Attr.X = -1;
  20.     Attr.Y = -1;
  21.     Attr.W = 10;
  22.     Attr.H = ( wHeight ) ? wHeight : 20 ;
  23.  
  24.     wAreas = 0;
  25.     hAreaText[10] = LocalAlloc (LMEM_MOVEABLE | LMEM_ZEROINIT, 1);
  26.     clrText[10] = 0 ;
  27.  
  28.     SetFlags(WB_MDICHILD, FALSE);
  29. }
  30.  
  31.  
  32. TStatusBar::~TStatusBar ()
  33. {
  34.     int    i;
  35.  
  36.     for (i=0 ; i < wAreas ; i++)
  37.     {
  38.         LocalFree (hAreaText[i]);
  39.     }
  40.  
  41.     LocalFree (hAreaText[10]);
  42. }
  43.  
  44. void TStatusBar::GetWindowClass(WNDCLASS& WndClass)
  45. {
  46.     TWindow::GetWindowClass( WndClass );
  47.     WndClass.hbrBackground = GetStockObject (LTGRAY_BRUSH); ;
  48. }
  49.  
  50. void TStatusBar::AppendArea (WORD length, LPSTR AString, COLORREF clrRef)
  51. {
  52.     rArea[wAreas] = length;
  53.     clrText[wAreas] = clrRef ;
  54.  
  55.     if ( AString )
  56.     {
  57.         hAreaText[wAreas] = LocalAlloc (LMEM_MOVEABLE | LMEM_ZEROINIT, _fstrlen(AString)+1);
  58.         LPSTR pDest = LocalLock (hAreaText[wAreas]);
  59.         _fstrcpy (pDest, AString);
  60.         LocalUnlock(hAreaText[wAreas]);
  61.     }
  62.     else
  63.     {
  64.         hAreaText[wAreas] = LocalAlloc (LMEM_MOVEABLE | LMEM_ZEROINIT, 1);
  65.     }
  66.  
  67.     wAreas++;
  68.  
  69.     InvalidateRect (HWindow, NULL, TRUE);
  70.     UpdateWindow (HWindow);
  71. }
  72.  
  73. BOOL TStatusBar::SetAreaText (WORD AreaId, LPSTR ANewString)
  74. {
  75.     int        n, xl, xr, i, j ;
  76.     RECT    rUpdate;
  77.     RECT    WndRect;
  78.  
  79.     GetClientRect (HWindow, &WndRect);
  80.     n = ( AreaId < wAreas ) ? AreaId : 10 ;
  81.     LocalFree (hAreaText[n]);
  82.  
  83.     if ( ANewString )
  84.     {
  85.         hAreaText[n] = LocalAlloc (LMEM_MOVEABLE | LMEM_ZEROINIT, _fstrlen(ANewString)+1);
  86.         LPSTR pDest = LocalLock (hAreaText[n]);
  87.         _fstrcpy (pDest, ANewString);
  88.         LocalUnlock(hAreaText[n]);
  89.     }
  90.     else
  91.         hAreaText[n] = LocalAlloc (LMEM_MOVEABLE | LMEM_ZEROINIT, 1);
  92.  
  93.     rUpdate.left = WndRect.left + 1;
  94.     rUpdate.right = 0 ;
  95.     j = 4 ;
  96.  
  97.     for (i = 0 ; i < n && i < wAreas ; i++)
  98.     {
  99.         j = 6 ;
  100.         rUpdate.left = rArea[i] ;
  101.     }
  102.  
  103.     if (n >= wAreas-1)
  104.         rUpdate.right = WndRect.right - 2 ;
  105.     else
  106.         rUpdate.right = rUpdate.left + rArea[i+1] - 1 ;
  107.  
  108.     rUpdate.left += j;
  109.     rUpdate.top = WndRect.top+3;
  110.     rUpdate.bottom = WndRect.bottom-5;
  111.     InvalidateRect (HWindow, &rUpdate, TRUE);
  112.     UpdateWindow (HWindow);
  113.     return TRUE ;
  114. }
  115.  
  116. BOOL TStatusBar::SetAreaTextColor (WORD AreaId, COLORREF clrRef)
  117. {
  118.     if ( AreaId < wAreas || AreaId == 10 )
  119.     {
  120.         clrText[AreaId] = clrRef ;
  121.         InvalidateRect (HWindow, NULL, TRUE);
  122.         UpdateWindow (HWindow);
  123.         return TRUE;
  124.     }
  125.  
  126.     return FALSE ;
  127. }
  128.  
  129. BOOL TStatusBar::SetAreaWidth (WORD AreaId, WORD wWidth)
  130. {
  131.     if ( AreaId < wAreas )
  132.     {
  133.         rArea[AreaId] = wWidth ;
  134.         InvalidateRect (HWindow, NULL, TRUE);
  135.         UpdateWindow (HWindow);
  136.         return TRUE;
  137.     }
  138.  
  139.     return FALSE ;
  140. }
  141.  
  142. BOOL TStatusBar::RemoveArea (WORD AreaId)
  143. {
  144.     if (AreaId < wAreas - 1)
  145.     {
  146.         LocalFree (hAreaText[AreaId]);
  147.  
  148.         for (int i = AreaId + 1 ; i < wAreas ; i++)
  149.         {
  150.             rArea[i-1] = rArea[i] ;
  151.             hAreaText[i-1] = hAreaText[i];
  152.             clrText[i-1] = clrText[i];
  153.         }
  154.  
  155.         wAreas--;
  156.     }
  157.     else
  158.     {
  159.         if ( AreaId == wAreas - 1 )
  160.         {
  161.             wAreas--;
  162.             LocalFree (hAreaText[wAreas]);
  163.         }
  164.         else
  165.             return FALSE ;
  166.     }
  167.  
  168.     InvalidateRect (HWindow, NULL, TRUE);
  169.     UpdateWindow (HWindow);
  170.     return TRUE ;
  171. }
  172.  
  173. void TStatusBar::Paint (HDC hdc, PAINTSTRUCT&)
  174. {
  175.     RECT    WndRect;
  176.     RECT    TextRect;
  177.     HPEN    hGrayPen;
  178.     WORD    x;
  179.     WORD    i;
  180.     WORD    n;
  181.     HFONT    hLabelFont, hOldFont ;
  182.     LPSTR    pText;
  183.  
  184.     GetClientRect (HWindow, &WndRect);
  185.     FrameRect (hdc, &WndRect, GetStockObject(BLACK_BRUSH));
  186.     hLabelFont = CreateFont (12, 0, 0, 0, 700, 0, 0, 0,    ANSI_CHARSET, OUT_DEFAULT_PRECIS,            //    cOutputPrecision
  187.                              OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, FF_SWISS | VARIABLE_PITCH,
  188.                              (LPSTR) "Arial");
  189.  
  190.     WndRect.left += 2;
  191.     WndRect.right--;
  192.     WndRect.top += 2;
  193.     WndRect.bottom-=2;
  194.     FrameRect (hdc, &WndRect, GetStockObject (GRAY_BRUSH));
  195.  
  196.     WndRect.left--;
  197.     WndRect.right--;
  198.     WndRect.top--;
  199.     WndRect.bottom--;
  200.     FrameRect (hdc, &WndRect, GetStockObject(WHITE_BRUSH));
  201.  
  202.     WndRect.left--;
  203.     WndRect.right += 2;
  204.     WndRect.top--;
  205.     WndRect.bottom +=3;
  206.  
  207.     hGrayPen = CreatePen (PS_SOLID, 1, 0x808080);
  208.     hOldFont = SelectObject (hdc, hLabelFont);
  209.     SetBkColor (hdc, 0x0C0C0C0);
  210.     x = WndRect.left+1;
  211.  
  212.     for (i=0, x=WndRect.left+1; i < wAreas; i++)
  213.     {
  214.         x += rArea[i];
  215.  
  216.         SelectObject (hdc, GetStockObject(WHITE_PEN));
  217.         MoveTo (hdc, x, WndRect.bottom-4);
  218.         LineTo (hdc, x, WndRect.top+1);
  219.         MoveTo (hdc, x+2, WndRect.bottom-4);
  220.         LineTo (hdc, x+2, WndRect.top+1);
  221.  
  222.         SelectObject (hdc, hGrayPen);
  223.         MoveTo (hdc, x+1, WndRect.bottom-3);
  224.         LineTo (hdc, x+1, WndRect.top);
  225.         MoveTo (hdc, x+3, WndRect.bottom-5);
  226.         LineTo (hdc, x+3, WndRect.top+1);
  227.  
  228.         SetTextColor (hdc, clrText[i]);
  229.         n = (i==0) ? 4 : 6 ;
  230.         pText = LocalLock (hAreaText[i]);
  231.         TextRect.left = x - rArea[i] + n;
  232.         TextRect.right = x-1;
  233.         TextRect.top = WndRect.top+3;
  234.         TextRect.bottom = WndRect.bottom-5;
  235.         ExtTextOut (hdc, x - rArea[i]+n, WndRect.top+3, ETO_CLIPPED, &TextRect, pText, _fstrlen(pText), NULL);
  236.         LocalUnlock (hAreaText[i]);
  237.     }
  238.  
  239.     SetTextColor (hdc, clrText[10]);
  240.     pText = LocalLock (hAreaText[10]);
  241.     TextRect.left = TextRect.right+2;
  242.     TextRect.right = WndRect.right-2;
  243.     TextRect.top = WndRect.top+3;
  244.     TextRect.bottom = WndRect.bottom-5;
  245.     x = TextRect.left + 4 ;
  246.     ExtTextOut (hdc, x, WndRect.top+3, ETO_CLIPPED, &TextRect, pText, _fstrlen(pText), NULL);
  247.     LocalUnlock (hAreaText[10]);
  248.  
  249.     SelectObject (hdc, hOldFont);
  250.     SelectObject (hdc, GetStockObject (BLACK_PEN));
  251.     DeleteObject (hGrayPen);
  252.     DeleteObject (hLabelFont);
  253. }
  254.  
  255. WORD TStatusBar::GetHeight ()
  256. {
  257.     return Attr.H;
  258. }
  259.  
  260.